﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TimeTest
{
    class TimeKeeper
    {
        int hours;
        int minutes;

        public int Hours
        {
            get
            {
                return hours;
            }
            set
            {
                if (value >= 24 || value < 0)
                {
                    if (value < 0)
                    {
                        hours = 24 + (value % 24);
                    }
                    else
                    {
                        hours = value % 24;
                    }
                }
                else
                {
                    hours = value;
                }
            }
        }

        public int Minutes
        {
            get
            {
                return minutes;
            }
            set
            {
                if (value >= 60||value<0)
                {
                    if (value < 0)
                    {
                        minutes = 60+(value % 60);
                        this.Hours = this.hours -1 + (value / 60);
                        Console.WriteLine();
                    }
                    else
                    {
                        minutes = value % 60;
                        this.Hours = this.hours + (value / 60);
                    }
                }
                else
                {
                    minutes = value;
                }
            }
        }

        public TimeKeeper(int hours, int minutes)
        {
            this.Hours = hours;
            this.Minutes = minutes;
        }

        public static TimeKeeper operator + (TimeKeeper keeper,int minutesToAdd)
        {

            keeper.Minutes = keeper.Minutes + minutesToAdd;
            return keeper;
        }
        public override string ToString()
        {
            string result = string.Format("it is {0} o'clock and {1} minutes",this.Hours,this.Minutes);
            return result;
        }

        public static TimeKeeper operator -(TimeKeeper keeper, int minutesToSubstract) 
        {
            keeper = keeper + (-minutesToSubstract);
            return keeper;
        }

        public static TimeKeeper operator ++(TimeKeeper keeper) 
        {
            keeper = keeper + 1;
            return keeper;
        }

        public static TimeKeeper operator --(TimeKeeper keeper) 
        {
            keeper = keeper -1;
            return keeper;
        }

        public override bool Equals(object obj)
        {
            TimeKeeper other = obj as TimeKeeper;
            if (this.Minutes == other.Minutes&&this.Hours==other.Hours) 
            {
                return true;
            }
            return false;
        }
    }
}
